package angels.client.Entities;
import java.util.ArrayList;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import angels.client.Activities.SharingActivity;

import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

import com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay;
import com.readystatesoftware.mapviewballoons.BalloonOverlayView;

public class CustomItemizedOverlay<Item extends OverlayItem> extends BalloonItemizedOverlay<CustomOverlayItem> {

	private ArrayList<CustomOverlayItem> m_overlays = new ArrayList<CustomOverlayItem>();
	private Context c;	
	
	public CustomItemizedOverlay(Drawable defaultMarker, MapView mapView) {
		super(boundCenter(defaultMarker), mapView);
		c = mapView.getContext();
	}

	public void addOverlay(CustomOverlayItem overlay) {
	    m_overlays.add(overlay);
	}

	public void update(){
		populate();
	}
	
	@Override
	protected CustomOverlayItem createItem(int i) {
		return m_overlays.get(i);
	}

	@Override
	public int size() {
		return m_overlays.size();
	}

	public void clear(){
		m_overlays.clear();	
	}
	
	@Override
	protected boolean onBalloonTap(int index, CustomOverlayItem item) {
		Sharing share=item.getShare();
		Intent intent= new Intent(c,angels.client.Activities.SharingActivity.class);
		intent.putExtra("username", share.getName());
		intent.putExtra("desc", share.getDescription());
		intent.putExtra("ctime", share.getDuration());
		intent.putExtra("rat", share.getUserRating());
		//intent.putExtra("bkey", share.getBusinessKey());
		intent.putExtra("likes", share.getLikes());
		intent.putExtra("dlikes", share.getDislikes());
		c.startActivity(intent);
		return true;
	}

	@Override
	protected BalloonOverlayView<CustomOverlayItem> createBalloonOverlayView() {
		// use our custom balloon view with our custom overlay item type:
		return new CustomBalloonOverlayView<CustomOverlayItem>(getMapView().getContext(), getBalloonBottomOffset());
	}	
}
